<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>产品列表展示</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }
        .container {
            max-width: 1200px;
            margin: auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
            border-radius: 8px;
            box-sizing: border-box;
        }
        .row {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
        }
        .col {
            flex: 0 0 calc(100% / 5 - 20px);
            max-width: calc(100% / 5 - 20px);
            box-sizing: border-box;
            padding: 10px;
            margin-bottom: 20px;
        }
        .card {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            cursor: pointer;
            transition: transform 0.2s;
            background-color: #ffffff;
            border: 1px solid #ddd;
            border-radius: 5px;
            height: 100%;
        }
        .card:hover {
            transform: scale(1.05);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }
        .product-img {
            width: 100%;
            height: 200px; /* 调整产品图片的高度 */
            object-fit: cover;
            border-top-left-radius: 5px;
            border-top-right-radius: 5px;
        }
        .card-body {
            padding: 8px;
            text-align: center;
        }
        .card-title {
            color: #333;
            margin-bottom: 10px;
            font-size: 20px;
        }
        .card-text {
            color: #666;
            font-size: 14px;
        }
        /* 替换为新的搜索框样式 */
        #searchInput {
            padding: 12px;
            border: 2px solid #007bff; /* 修改边框样式和颜色 */
            border-radius: 5px;
            width: 100%;
            max-width: 300px;
            margin-bottom: 20px;
            box-sizing: border-box;
            font-size: 16px;
            outline: none; /* 去掉默认的蓝色外边框 */
        }

        #searchInput::placeholder {
            color: #999;
        }

        #searchInput:focus {
            border-color: #0056b3; /* 设置获取焦点时的边框颜色 */
        }

        @media (max-width: 992px) {
            .col {
                flex: 0 0 calc(100% / 3 - 20px);
                max-width: calc(100% / 3 - 20px);
            }
        }

        @media (max-width: 576px) {
            .col {
                flex: 0 0 calc(100% / 1 - 20px);
                max-width: calc(100% / 1 - 20px);
            }
        }
    </style>
</head>
<body>

<div class="container">
    <h2>产品列表</h2>
    <input type="text" id="searchInput" class="form-control mb-3" placeholder="搜索产品...">
    <div id="productList" class="row">
        {% for row in rows %}
        <div class="col mb-4" onclick="location.href='/product_info/{{ row[0] }}';" style="cursor: pointer;">
            <div class="card">
                <img src="{{ url_for('static', filename=row[9]) }}" class="card-img-top product-img" alt="{{ row[3] }}">
                <div class="card-body">
                    <h5 class="card-title">{{ row[3] }}</h5>
                    <p class="card-text">规格型号：{{ row[4] }}</p>
                    <p class="card-text">颜色：{{ row[5] }}</p>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
</div>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        const searchInput = document.getElementById('searchInput');
        const products = document.querySelectorAll('#productList .col');

        searchInput.addEventListener('input', function() {
            const searchText = searchInput.value.toLowerCase();

            products.forEach(function(product) {
                const title = product.querySelector('.card-title').textContent.toLowerCase();
                const modelText = product.querySelectorAll('.card-text')[0].textContent.toLowerCase();
                const colorText = product.querySelectorAll('.card-text')[1].textContent.toLowerCase();

                if (title.includes(searchText) || modelText.includes(searchText) || colorText.includes(searchText)) {
                    product.style.display = '';
                } else {
                    product.style.display = 'none';
                }
            });
        });
    });
</script>

</body>
</html>
